package com.lwp.demo.js;

import com.lwp.demo.js.translation.JavaScriptTranslationProcessor;
import com.lwp.demo.js.translation.JavaScriptTranslationProcessorTest;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class JsApplication {

    public static void main(String[] args) {

        String line = "sfwe // fwef3 // /";
        String[] split1 = StringUtils.split(line, "//", 2);
        for (String s: split1) {
            System.out.println(s);
        }
        System.out.println(Arrays.asList(split1));

        String srcFile = "E:\\git\\lwp-examples\\js-demo\\src\\main\\resources\\test.js";
        JavaScriptTranslationProcessor javaScriptTranslationProcessor = new JavaScriptTranslationProcessor(srcFile);
//        javaScriptTranslationProcessor.translation();

        JavaScriptTranslationProcessorTest javaScriptTranslationProcessor1 = new JavaScriptTranslationProcessorTest(srcFile);
        javaScriptTranslationProcessor1.translation();



        String str = "fwe'f可以 ''看看无法违法'123  '了科技服务了卡'";

        String regex = "[\\u4e00-\\u9fa5]+";
        Pattern compile = Pattern.compile(regex);
        Matcher matcher = compile.matcher(str);
        while (matcher.find()) {
            System.out.println(matcher.group());
//            System.out.println(matcher.group(1));
        }

        try {
            test();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void test() throws IOException {
        String srcFile = "E:\\git\\lwp-examples\\js-demo\\src\\main\\resources\\test.js";
        List<String> list = IOUtils.readLines(new FileReader(new File(srcFile)));
        StringBuilder sb = new StringBuilder();
        for (String s: list) {
            sb.append(s);
        }
        String regex = "[\\u4e00-\\u9fa5]+";
        Pattern compile = Pattern.compile(regex);
        Matcher matcher = compile.matcher(sb.toString());
        while (matcher.find()) {
            System.out.println(matcher.group());
        }
    }

}
